﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using System.Text.RegularExpressions; 

namespace GUI
{
    [Serializable()]
    public class Textbox : Textfield
    {
        private KeyboardState oldKeyboardState, currentKeyboardState;

        private void UpdateInput()
        {
            oldKeyboardState = currentKeyboardState;
            currentKeyboardState = Keyboard.GetState();

            Keys[] pressedKeys;
            pressedKeys = currentKeyboardState.GetPressedKeys();

            foreach (Keys key in pressedKeys)
            {
                if (oldKeyboardState.IsKeyUp(key))
                {
                    if (key == Keys.Back) // overflows
                        Text = Text.Remove(Text.Length - 1, 1);
                    else
                        if (key == Keys.Space)
                            Text = Text.Insert(Text.Length, " ");
                        else
                        {
                            if (Keyboard.GetState().IsKeyDown(Keys.LeftShift) || Keyboard.GetState().IsKeyDown(Keys.RightShift))
                            {
                                Text += key.ToString();
                            }
                                else
                                {
                            Text += key.ToString().ToLower();
                                }

                        }
                }
            }
        }

        public override void Update()
        {
            UpdateInput();
        }
    }
}
